package com.itboye.ihomebank.util;

import java.text.DecimalFormat;

/**
 * Created by Mr.w on 2017/2/17.
 */

public class DoubleUtil {
    public static String getDouble(String value) {
        double num = Double.parseDouble(value) / 100;
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(num);
    }

    public static double getDoubleTwo(String value) {
        double num = Double.parseDouble(value);
        return (num);
    }

    /**
     * double类型转String 类型的小数点后的00
     *
     * @param num double参数
     * @return String 类型
     */
    public static String doubleTransform(String num) {
        String strNum = num + "";
        String newNum = Double.parseDouble(strNum) / 100 + "";
        int a = newNum.indexOf(".");
        if (a > 0) {
            //获取小数点后面的数字
            String dianAfter = newNum.substring(a + 1);
            if ("0".equals(dianAfter)) {
                return newNum + "0";
            } else {
                if (dianAfter.length() == 1) {
                    return newNum + "0";
                } else {
                    return newNum;
                }
            }
        } else {
            return newNum + ".00";
        }
    }
}
